package homework;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class SortReducer extends Reducer<LongWritable, NullWritable, IntWritable, LongWritable> {

    IntWritable v = new IntWritable();

    int i = 1;

    @Override
    protected void reduce(LongWritable key, Iterable<NullWritable> values, Context context) throws IOException, InterruptedException {

        // 遍历values，因为存在相同的key，并且需要全部输出
        for (NullWritable ignored : values) {
            v.set(i++);
            context.write(v, key);
        }
    }
}
